//
//  PhotoViewController.swift
//  DMCamera
//
//  Created by 李浩 on 2017/8/3.
//  Copyright © 2017年 李浩. All rights reserved.
//

import UIKit
import Photos

class PhotoViewController: UIViewController {

    var assetColls: [PHAssetCollection] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        view.addSubview(tv)
        configPhoto()
        
        tv.itemClick = {coll in
            let dc = PhotoDetailController()
            dc.collection = coll
            self.navigationController?.pushViewController(dc, animated: true)
        }
    }
    
    func configPhoto() {
        let photos: PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)
        photos.enumerateObjects({ (collection, num, pointer) in
            if (num > 0) {
                self.assetColls.append(collection)
            }
//            let asset = PHAsset.fetchAssets(in: collection, options: nil)
//            asset.enumerateObjects({ (asset, anum, apointer) in
//
//            })
        })
        self.tv.dataArr = assetColls
        self.tv.reloadData()
    }
    
    lazy var tv: PhotoTableView = {
        let table = PhotoTableView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height), style: .plain)
        return table
    }()

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func popAction(_ sender: Any) {
        navigationController?.popViewController(animated: true)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
